const images = require('images');

function render(viewport, element) {
  if (element.style) {
    let img = images(element.style.width, element.style.height);

    if (element.style['background-color']) {
      let color = element.style['background-color'] || 'rgb(0,0,0)';
      color.match(/rgb\((\d+),(\d+),(\d+)\)/);
	  let r=RegExp.$1
	  let g=RegExp.$2
	  let b=RegExp.$3
	  
	  //console.log("---------color=%s, r=%s ,g=%s, b=%s",color,r,g,b)
	  
      img.fill(Number(r), Number(g), Number(b));
      viewport.draw(img, element.style.left || 0, element.style.top || 0);
    }
  }

  if (element.children) {
	
    for (let child of element.children) {
		//console.log("child------------------",child)
      render(viewport, child);
    }
  }
}

module.exports = render;